home *** CD-ROM | disk | FTP | other *** search
- /** SpellFix.ttx
- *
- * Interface to ISpell to spellfix an entire file. To be called from
- * inside Turbotext. If an argument "all" is given, then "closest root"
- * errors will also be flagged.
- *
- * W.G.J. Langeveld, April 1992.
- *
- * Hacked by Loren to try to adhere to the new extendedfilecheck
- * method instead of the custom ISpell method that Willy used.
- *
- * Loren J. Rittle, Fri Nov 20 01:51:22 1992
- *
- **/
- parse arg allfix
-
- options results
- options failat 100
- /*
- * Allow no interruptions so we can cleanup
- */
- SIGNAL ON BREAK_C
- SIGNAL ON BREAK_D
- SIGNAL ON BREAK_E
- SIGNAL ON BREAK_F
- SIGNAL ON FAILURE
- SIGNAL ON HALT
- SIGNAL ON SYNTAX
- /*
- * Get the screen size and name according to TTX. Set the TTX window
- * size such that there is room for the requester.
- */
- "getscreeninfo"
- info = result
- parse var info x x x x x cols rows myspellscreen
- /*
- * Check if file has been saved. If not, save it.
- */
- "getfileinfo"
- parse var result x changes x .
- if changes = "YES" then "savefile"
- /*
- * Change TTX's window size and put up the spellfix requester
- */
- call SpellRequest(cols, rows, myspellscreen)
- /*
- * Start ISpell if it isn't running yet.
- */
- if ~showlist("p", "IRexxSpell") then do
- call SpellMsg("ISpell not running, starting ISpell")
- address COMMAND "run >nil: <nil: ISpell -R"
- do i = 1 to 50
- call delay(50)
- if showlist("p", "IRexxSpell") then leave i
- end
- if ~showlist("p", "IRexxSpell") then signal ERROR:
- end
- /*
- * Get the file name, spellcheck the file quickly.
- */
- "GetFilePath"
- name = result
- address "IRexxSpell" extendedfilecheck name
-
- "SetDisplayLock ON"
- spellword. = ""
- do i = 1 to ispellresult.count
- /*
- * Get location of spell error
- */
- spellword.i = ispellresult.i.word
- y = ispellresult.i.line
- x = ispellresult.i.column
- /*
- * Get the line it is in
- */
- "Move Folds" y 1
- "GetLine"
- line = result
- /*
- * If the spell error is somewhere in the line, untab the part
- * before it to find the real column number.
- */
- if x ~= 1 then do
- firstpart = substr(line, 1, x - 1)
- firstpart = untab(firstpart)
- x = length(firstpart) + 1
- end
- /*
- * Now set a bookmark there.
- */
- "Move Folds" y x
- "SetBookmark" 1000 + i
- end
-
- /*
- * Get number of lines, etc. and move to the start of the file.
- */
- "GetFileInfo"
- parse var result nlines mods name
- "MoveSOF"
- test = 1
-
- /*
- * Loop over the errors (bookmarks).
- */
- do i = 1 to ispellresult.count
- "MoveBookmark" 1000 + i
-
- item = spellword.i
- /*
- * See if the word under the cursor is indeed what we think it is.
- * If not, see if this line *has* a word like that.
- */
- "GetWord"
- if result ~= item then do
- "GetLine"
- line = result
- line = untab(line)
- line = translate(line,,
- "[]{}(),.;:/<>:?`~!@#$%^&*_+|-=\|"||'"'||'0a'x||'09'x)
- /*
- * Loop over the words in the line
- */
- place = 0
- n = words(line)
- do j = 1 to n
- if word(line, j) = item then do
- place = wordindex(line, j)
- leave j
- end
- end
- /*
- * If the line no longer has the word, we assume it was fixed.
- */
- if place = 0 then iterate i
- /*
- * Otherwise, we'll position ourselves at that word.
- */
- "GetCursorPos"
- parse var result y x .
- "Move folds" y place
- end
-
- address "IRexxSpell" check item
- /*
- * Find out what ISpell thought about this one
- */
- r = result
- r1 = substr(r, 1, 1)
- string = ""
- alternatives = ""
- select
- when r1 = '*' then do
- end
- when r1 = '&' then do
- string = '"'item||'" not found. Click on Select for alternatives.'
- alternatives = substr(r, 3)
- end
- when r1 = '#' then do
- string = '"'item||'" not found.'
- end
- when r1 = '+' then do
- if allfix ~= "" then do
- string = '"'||item||'" not found. Closest root:' substr(r, 3)
- end
- end
- otherwise string = '"'||item||'":' r
- end
- /*
- * If we have a result string, then put the cursor at the offending
- * location and ask the user what to do about it.
- */
- if string ~= "" then do
- "SetDisplayLock OFF"
- test = GetNextMsg(item, string, alternatives)
- if test = 0 then leave i
- "SetDisplayLock ON"
- end
- end
-
- /**
- *
- * Clean up
- *
- **/
- BREAK_C:
- BREAK_D:
- BREAK_E:
- BREAK_F:
- ERROR:
- FAILURE:
- HALT:
- SYNTAX:
-
- "SetDisplayLock OFF"
- if showlist('p', 'SPELLREQUEST') then do
- /*
- * End of document. Give user chance to do more stuff.
- */
- if test ~= 0 then do i = 1
- test = GetNextMsg(" ", "All done!", "")
- if test = 0 then leave i
- end
-
- call CloseWindow(SPELLREQUEST)
- "MoveWindow 0 -55"
- "SizeWindow 0 55"
- end
- exit
-
-
- /** untab
- *
- * Expand tabs in a line.
- *
- **/
- untab: Procedure
- parse arg line
-
- "getprefs tabwidth"
- tabsetting = result
-
- do forever
- n = index(line, '09'x)
- if n = 0 then return line
- nspaces = tabsetting - ((n - 1) // tabsetting)
- line = insert(" ", delstr(line, n, 1), n - 1, nspaces, " ")
- end
-
-
- /** SpellRequest
- *
- * This program brings up a spell requester
- *
- * Add the libraries if they're not there yet.
- *
- **/
- SpellRequest: Procedure
- parse arg cols, rows, myspellscreen
-
- if show("l", "rexxarplib.library") = 0 then do
- check = addlib('rexxsupport.library', 0, -30, 0)
- check = addlib('rexxarplib.library', 0, -30, 0)
- check = addlib('rexxmathlib.library', 0, -30, 0)
- end
- /*
- * Set the TTX window size such that there is room for the requester.
- */
- "sizewindow 0 -55"
- "movewindow 0 55"
-
- mp = OpenPort(MYSPELLPORT)
- /*
- * Set up a host. This time, send all messages to MYSPELLPORT.
- */
- address AREXX "'x = CreateHost(SPELLREQUEST, MYSPELLPORT, "myspellscreen")'"
- /*
- * Wait until it is ready.
- */
- do i = 1
- if showlist('p', SPELLREQUEST) ~= 0 then leave
- call delay 30
- end
- /*
- * Open the window
- */
- idcmp = 'CLOSEWINDOW+GADGETUP+MENUPICK'
- flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+ACTIVATE'
-
- call OpenWindow(SPELLREQUEST, 0, 0, cols, 55, idcmp, flags, "ISpell Control")
- /*
- * Add the gadgets
- */
- call AddMenu(SPELLREQUEST, "Commands")
-
- call AddItem(SPELLREQUEST, " Add to Temporary Dictionary", "ADD", "A", 0)
- call AddItem(SPELLREQUEST, " Go to Next Error", "IGNORE", "N", 0)
- call AddItem(SPELLREQUEST, " Select Alternatives", "SELECT", "L", 0)
- call AddItem(SPELLREQUEST, " Search/Replace", "SR", "R", 0)
- call AddItem(SPELLREQUEST, " Save Dictionary Additions", "SAVE", "S", 0)
- call AddItem(SPELLREQUEST, " Exit ISpell", "EXIT", "E", 0)
- call AddItem(SPELLREQUEST, " Leave (ISpell stays running)", "CLOSEWINDOW", "Q", 0)
-
- call AddGadget(SPELLREQUEST, 20, 17, 1, " Add ", "ADD")
- call AddGadget(SPELLREQUEST, 70, 17, 2, " Next ", "IGNORE")
- call AddGadget(SPELLREQUEST, 128, 17, 3, " Select ", "SELECT")
- call AddGadget(SPELLREQUEST, 222, 17, 4, " S/R ", "SR")
- call AddGadget(SPELLREQUEST, 292, 17, 5, " Save Additions ", "SAVE")
- call AddGadget(SPELLREQUEST, 430, 17, 6, " Exit ISpell ", "EXIT")
- call AddGadget(SPELLREQUEST, 544, 17, 7, " Leave ", "CLOSEWINDOW")
-
- /*
- * Display a "Checking..." string
- */
- call SpellMsg("Checking...")
-
- return 1
-
- /** SpellMsg
- *
- * Display a line in the spell requester
- *
- **/
- SpellMsg: Procedure
- parse arg line
-
- call WindowText(SPELLREQUEST, "\\"line)
-
- return
-
- /** GetNextMsg
- *
- * GetNextMsg gets the next message from MYSPELLPORT. Arguments are
- * the word that led to this call and the string we got from ISpell.
- *
- **/
- GetNextMsg: Procedure
- parse arg item, string, alternatives
- /*
- * Display the string, after wrapping it if needed.
- */
- call SpellMsg(string)
- /*
- * Make a list of alternatives
- */
- if alternatives ~= "" then do
- wordlist.0 = words(alternatives)
- do i = 1 to wordlist.0
- wordlist.i = word(alternatives, i)
- end
- call SetGadget(SPELLREQUEST, 3, ON)
- end
- /*
- * In case the user wants to do a search/replace, set up the find string
- */
- "SetPrefs FindString "item
-
- restart:
- /*
- * Check if there are any more messages. This procedure does not
- * WaitPkt unless there aren't any messages.
- */
- do i = 1
- p = getpkt(MYSPELLPORT)
- if p = NULL() then do
- call waitpkt(MYSPELLPORT)
- p = getpkt(MYSPELLPORT)
- if p = NULL() then iterate i
- end
- leave i
- end
- call SetGadget(SPELLREQUEST, 3, OFF)
- /*
- * There's a message.
- */
- thisarg = getarg(p)
- t = reply(p, 0)
- /*
- * Do what needs to be done
- */
- select
- when (thisarg = "CLOSEWINDOW") | (thisarg = "EXIT") then do
- if thisarg = "EXIT" then address "IRexxSpell" exit
- return 0
- end
- when thisarg = "IGNORE" then do
- call SpellMsg("Continuing...")
- return 1
- end
- when thisarg = "ADD" then do
- address "IRexxSpell" quickadd item
- call SpellMsg("Continuing...")
- return 1
- end
- when thisarg = "SAVE" then do
- address "IRexxSpell" add
- call SpellMsg("Continuing...")
- return 1
- end
- when thisarg = "SR" then do
- "OpenRequester FindChange"
- signal restart:
- end
- when thisarg = "SELECT" then do
- if show('p', 'QuickSortPort') & (alternatives ~= "") then do
- /*
- * Get the screen size and name according to TTX. Set the TTX window
- * size such that there is room for the requester.
- */
- "getscreeninfo"
- info = result
- parse var info x x x x x cols rows myspellscreen
-
- call ListRequest(1, wordlist.0, wordlist, selected, 128, 30, ,
- 280, 170, myspellscreen, SORT)
- if selected ~= "" then do
- "SetPrefs ChangeString "selected
- "GetWord"
- if result = item then do
- "ReplaceWord" selected
- line = "Replaced."
- end
- else do
- line = "Word under cursor not the same! Not corrected."
- end
- call SpellMsg(line)
- end
- end
- else do
- call SpellMsg("No alternatives found.")
- end
- signal restart:
- end
- end
-